import { getList, getWorkshop } from '@/api/api';
import { nextTick } from 'process';
export function formattedDate(e) {
  const timestamp = e;
  const date = new Date(timestamp);
  const year = date.getFullYear();
  const month = ('0' + (date.getMonth() + 1)).slice(-2);
  const day = ('0' + date.getDate()).slice(-2);
  const hours = ('0' + date.getHours()).slice(-2);
  const minutes = ('0' + date.getMinutes()).slice(-2);
  const seconds = ('0' + date.getSeconds()).slice(-2);
  const formattedDate =
    year + '-' + month + '-' + day + ' ' + hours + ':' + minutes + ':' + seconds;
  return formattedDate;
}
export const schemasManage: FormSchema[] = [
  {
    field: 'unit',
    component: 'NInput',
    label: '单位名称',
    componentProps: {
      placeholder: '搜索单位名称',
      onInput: (e: any) => {
        console.log(e);
      },
    },
  },
  {
    field: 'workshop',
    component: 'NInput',
    label: '车间名称',
    componentProps: {
      placeholder: '搜索车间名称',
      onInput: (e: any) => {
        console.log(e);
      },
    },
  },
  {
    field: 'encode',
    component: 'NInput',
    label: '编码',
    componentProps: {
      placeholder: '搜索编码',
      onInput: (e: any) => {
        console.log(e);
      },
    },
  },
  {
    field: 'status',
    component: 'NInput',
    label: '状态',
    componentProps: {
      placeholder: '搜索状态',
      onInput: (e: any) => {
        console.log(e);
      },
    },
  },
  {
    field: 'scrap_time',
    component: 'NDatePicker',
    label: '报废日期',
    componentProps: {
      type: 'daterange',
      onInput: (e: any) => {
        console.log(e);
      },
    },
  },
  {
    field: 'scrap_time',
    component: 'NDatePicker',
    label: '临近维修',
    componentProps: {
      type: 'daterange',
      onInput: (e: any) => {
        console.log(e);
      },
    },
  },
];
export const schemasUser: FormSchema[] = [
  {
    field: 'unit',
    component: 'NInput',
    label: '',
    componentProps: {
      placeholder: '请输入单位名称',
      onInput: (e: any) => {
        console.log(e);
      },
    },
  },
];
export const schemasUserModal: FormSchema[] = [
  {
    field: 'unit',
    component: 'NInput',
    label: '单位名称：',
    giProps: {
      span: 1,
    },
    componentProps: {
      placeholder: '请输入单位名称',
      onInput: (e: any) => {
        console.log(e);
      },
    },
  },
  {
    field: 'username',
    component: 'NInput',
    label: '账号：',
    componentProps: {
      placeholder: '请输入账号',
      showButton: false,
      onInput: (e: any) => {
        console.log(e);
      },
    },
  },
  {
    field: 'password',
    component: 'NInput',
    label: '密码：',
    componentProps: {
      type: 'password',
      placeholder: '请输入密码',
      showButton: false,
      onInput: (e: any) => {
        console.log(e);
      },
    },
  },
  {
    field: 'codes_num',
    component: 'NInput',
    label: '二维码数量：',
    componentProps: {
      type: 'Number',
      placeholder: '请输入二维码数量',
      showButton: false,
      onInput: (e: any) => {
        console.log(e);
      },
    },
  },
];
getList().then((res) => {
  // schemasWorkshop.value.options=res.data
  let result = [];
  res.data.forEach((item) => {
    result.push({
      label: item.unit,
      value: item.id,
    });
  });
  console.log(result);
  schemasWorkshop[0].componentProps.options = result;
  schemasExternalworkShop[2].componentProps.options = result;
  schemasManageModal[0].componentProps.options = result;
});
// 车间账号添加
export const schemasWorkshop: FormSchema[] = [
  {
    field: 'unit_id',
    component: 'NSelect',
    label: '所属单位：',
    componentProps: {
      placeholder: '请选择',
      options: [],
      onUpdateValue: (e: any) => {},
    },
  },
  {
    field: 'workshop',
    component: 'NInput',
    label: '车间名称',
    giProps: {
      span: 1,
    },
    componentProps: {
      placeholder: '请输入车间',
      onInput: (e: any) => {
        console.log(e);
      },
    },
  },
  {
    field: 'username',
    component: 'NInput',
    label: '账号：',
    componentProps: {
      placeholder: '请输入账号',
      showButton: false,
      onInput: (e: any) => {
        console.log(e);
      },
    },
  },
  {
    field: 'password',
    component: 'NInput',
    label: '密码：',
    componentProps: {
      type: 'password',
      placeholder: '请输入密码',
      showButton: false,
      onInput: (e: any) => {
        console.log(e);
      },
    },
  },
];

// 外部单位账号添加
export const schemasExternalUnit: FormSchema[] = [
  {
    field: 'unit',
    component: 'NInput',
    label: '单位名称：',
    componentProps: {
      placeholder: '请输入单位名称',
    },
  },

  {
    field: 'username',
    component: 'NInput',
    label: '账号：',
    componentProps: {
      placeholder: '请输入账号',
      showButton: false,
      onInput: (e: any) => {
        console.log(e);
      },
    },
  },
  {
    field: 'password',
    component: 'NInput',
    label: '密码：',
    componentProps: {
      type: 'password',
      placeholder: '请输入密码',
      showButton: false,
      onInput: (e: any) => {
        console.log(e);
      },
    },
  },
  {
    field: 'codes_num',
    component: 'NInput',
    label: '二维码数量：',
    componentProps: {
      type: 'number',
      placeholder: '请输入二维码数量',
      showButton: false,
      onInput: (e: any) => {
        console.log(e);
      },
    },
  },
  {
    field: 'max_num',
    component: 'NInput',
    label: '灭火器上限数量：',
    componentProps: {
      type: 'number',
      placeholder: '请输入二维码数量',
      showButton: false,
      onInput: (e: any) => {
        console.log(e);
      },
    },
  },
  {
    field: 'expiration_time',
    component: 'NDatePicker',
    label: '到期日期',
    componentProps: {
      type: 'date',
      clearable: true,
      onUpdateValue: (e: any) => {},
    },
  },
  {
    field: 'annual_check',
    component: 'NDatePicker',
    label: '年检日期',
    componentProps: {
      type: 'date',
      clearable: true,
      onUpdateValue: (e: any) => {},
    },
  },
];

// 外部车间账号
export const schemasExternalworkShop: FormSchema[] = [
  {
    field: 'id',
    component: 'NInput',
    label: 'ID',
    componentProps: {
      placeholder: '请输入ID',
    },
  },
  {
    field: 'workshop',
    component: 'NInput',
    label: '车间名称：',
    componentProps: {
      placeholder: '请输入车间名称',
    },
  },
  {
    field: 'name',
    component: 'NSelect',
    label: '所属单位：',
    componentProps: {
      placeholder: '请选择',
      options: [
        {
          label: '是',
          value: 1,
        },
        {
          label: '否',
          value: 2,
        },
      ],
      onUpdateValue: (e: any) => {},
    },
  },

  {
    field: 'username',
    component: 'NInput',
    label: '账号：',
    componentProps: {
      placeholder: '请输入账号',
      showButton: false,
      onInput: (e: any) => {
        console.log(e);
      },
    },
  },
  {
    field: 'password',
    component: 'NInput',
    label: '密码：',
    componentProps: {
      type: 'password',
      placeholder: '请输入密码',
      showButton: false,
      onInput: (e: any) => {
        console.log(e);
      },
    },
  },
];

export const schemasManageModal: FormSchema[] = [
  {
    field: 'unit_id',
    component: 'NSelect',
    label: '所属单位：',
    componentProps: {
      placeholder: '请选择',
      options: [],
      onUpdateValue: (e: any) => {
        console.log(e);
        getWorkshop({ unit_id: e }).then((res) => {
          let result = [];
          res.data.forEach((item) => {
            result.push({
              label: item.workshop,
              value: item.id,
            });
          });
          console.log(schemasManageModal[1]);
          schemasManageModal[2].componentProps.options.push(...result);
        });
      },
    },
  },
  {
    field: 'site',
    component: 'NInput',
    label: '灭火器放置地址',
  },
  {
    field: 'workshop_id',
    component: 'NSelect',
    label: '车间名称',
    componentProps: {
      placeholder: '请选择',
      options: [],
      onUpdateValue: (e: any) => {},
    },
  },
  {
    field: 'product_name',
    component: 'NSelect',
    label: '产品名称',
    componentProps: {
      placeholder: '请选择',
      options: [
        {
          label: '二氧化碳灭火器',
          value: '二氧化碳灭火器',
        },
        {
          label: '水基灭火器',
          value: '水基灭火器',
        },
        {
          label: '干粉灭火器',
          value: '干粉灭火器',
        },
        {
          label: '七氟丙烷灭火器',
          value: '七氟丙烷灭火器',
        },
        {
          label: '超细干粉灭火器',
          value: '超细干粉灭火器',
        },
      ],
      onUpdateValue: (e: any) => {},
    },
  },
  {
    field: 'factory',
    component: 'NInput',
    label: '生产厂家',
    giProps: {
      span: 1,
    },
    componentProps: {
      placeholder: '',
      onInput: (e: any) => {
        console.log(e);
      },
    },
  },

  {
    field: 'model',
    component: 'NInput',
    label: '型号',
    giProps: {
      span: 1,
    },
  },
  {
    field: 'produce_time',
    component: 'NDatePicker',
    label: '生产日期',
    componentProps: {
      type: 'date',
    },
  },
  {
    field: 'scrap_time',
    component: 'NDatePicker',
    label: '报废日期',
    componentProps: {
      type: 'date',
    },
  },
  {
    field: 'repair_time',
    component: 'NDatePicker',
    label: '维修日期',
    componentProps: {
      type: 'date',
    },
  },
  {
    field: 'next_repair_time',
    component: 'NDatePicker',
    label: '下次维修日期',
    componentProps: {
      type: 'date',
    },
  },
  {
    field: 'pressure_time',
    component: 'NDatePicker',
    label: '水压试测日期',
    componentProps: {
      type: 'date',
    },
  },
  {
    field: 'next_pressure_time',
    component: 'NDatePicker',
    label: '下次水压试验日期',
    componentProps: {
      type: 'date',
    },
  },
  {
    field: 'powder_time',
    component: 'NDatePicker',
    label: '粉剂更换日期',
    componentProps: {
      type: 'date',
    },
  },
  {
    field: 'next_powder_time',
    component: 'NDatePicker',
    label: '下次粉剂更换时间',
    componentProps: {
      type: 'date',
    },
  },
  {
    field: 'annual_check',
    component: 'NDatePicker',
    label: '年检日期',
    componentProps: {
      type: 'date',
    },
  },
  // {
  //   field: 'name',
  //   component: 'NInput',
  //   label: '灭火器编码',
  // },
];
